<?php
namespace App\Common;
use Storage;


class Result
{
    /**
     * 是否为空
     * @param $params
     * @param $name
     * @param int $code
     * @return bool
     */
    public static function isEmpty($params, $name, $code = '201')
    {
        if(empty($params)){
            self::msg($code,'error',$name);
        }else{
            return true;
        }
    }

    /**
     * 信息输出
     * @param $code
     * @param null $status
     * @param null $data
     */
    public static function msg($code, $info = '', $data )
    {

        //数组处理
        /*if(is_array($data)){
            $datas = $data;
        }else{
            if(!$data)
                $datas = array();
            else
                $datas = array(
                    $data
                );
        }*/
        $array = array(
            'code' => $code,
            'message' => $info
        );

        if(is_array($data)){
            if(array_key_exists(0,$data) || empty($data)){
                $array['list'] = $data;
            }else{
                $array['list'] = array(
                    $data
                );
            }
        }else{
            if(!$data)
                $array['list'] = '';
            else
                $array['list'] = $data;
        }



        exit(json_encode($array, JSON_UNESCAPED_UNICODE));
    }

    /**
     * 密码加密
     * @param $password
     * @return string
     */
    public static function md5_pwd($password)
    {
        $password = md5($password);
        $password = md5($password);
        return $password;
    }

    /**
     * 上传文件
     */
    public function uploadFile()
    {

    }

    /**
     * 评论过短
     */
    public static function veryShort($data)
    {
        $lenght = strlen($data);
        if($lenght < 2){
            self::msg('-17','error','内容过短');
        }
        return true;
    }
}